package com.clms.system.controller;

import com.clms.common.R;
import com.clms.system.myconfig.LogAnnotation;
import com.clms.system.pojo.entitry.SysMenu;
import com.clms.system.pojo.vo.OnlyoneVo;
import com.clms.system.service.MenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.*;

/**
 * @program: clms-third
 * @description:
 * @author: 大鱼
 * @create: 2021-07-19 14:42
 **/
@RestController
@Api(value = "生成动态菜单")
@EnableAspectJAutoProxy
public class MenuController {
    @Autowired
    MenuService menuService;
    @ApiOperation(value = "")
    @GetMapping("/system/test")
    public R test(HttpSession session) {
        System.out.println(session.getServletContext().getRealPath("static"));

        return null;
    }
    @GetMapping("system/menu")
    @ApiOperation(value = "根据id查找左侧的方法")
    @LogAnnotation(title = "动态左侧",businessType = "1",action = "3")
    public R findleftmenu() {
        return menuService.findleftmenubyuserid();
    }
    @ApiOperation(value = "获取用户菜单")
    @LogAnnotation(title = "查询",businessType = "1",action = "3")
    @GetMapping("system/menu/getMenuByRoleId/{roleId}")
    public R getMenuByRoleId(@PathVariable Integer roleId) {
        return menuService.getMenuByRoleId(roleId);
    }
    @ApiOperation(value = "用户分菜单")
    @LogAnnotation(title = "分菜单",businessType = "1",action = "3")
    @GetMapping("system/menu/confirmFenMenu")
    public R confirmFenMenu(@RequestParam Integer roleId, @RequestParam List<Integer> roleMenuIds) {
        return menuService.saveRoleMenu(roleId, roleMenuIds);
    }
    @LogAnnotation(title = "查询菜单",businessType = "1",action = "3")
    @ApiOperation(value = "获取所有菜单")
    @GetMapping("/system/menu/getallmenu")
    public R getAllMenu() {
        return menuService.getAllMenu();
    }
    @ApiOperation(value = "根据Id获取菜单")
    @LogAnnotation(title = "查询菜单",businessType = "1",action = "3")
    @GetMapping("/system/menu/getmenubyid/{menuId}")
    public R getMenuById(@PathVariable("menuId") Integer menuId) {
        return menuService.getMenuById(menuId);
    }
    @ApiOperation(value = "增加或者更新菜单")
    @LogAnnotation(title = "更新菜单表",businessType = "1",action = "3")
    @PostMapping("/system/menu/addorupdate")
    public R addOrUpdateMenu(@RequestBody SysMenu menu) {
        return menuService.addOrUpdateMenu(menu);
    }
    @LogAnnotation(title = "查询",businessType = "1",action = "3")
    @ApiOperation(value = "名称唯一校验")
    @PostMapping("/system/menu/onlyonecheck/bymenuname")
    public R onlyOneCheckName(@RequestBody OnlyoneVo onlyoneVo) {
        return menuService.onlyOneCheckonlyOneCheck(onlyoneVo);
    }
    @LogAnnotation(title = "查询",businessType = "1",action = "3")
    @ApiOperation(value = "url唯一校验")
    @PostMapping("/system/menu/onlyonecheck/byurl")
    public R onlyOneCheckUrl(@RequestBody OnlyoneVo onlyoneVo) {
        return menuService.onlyOneCheckonlyOneCheckUrl(onlyoneVo);
    }

    @ApiOperation(value = "菜单下拉")
    @GetMapping("/system/menu/menulist")
    public R getMenuList() {
        return menuService.getMenuList();
    }

    @ApiOperation(value = "菜单删除")
    @DeleteMapping("/system/menu/remove/{menuId}")
    public R removeMenuByid(@PathVariable("menuId") Integer menuId) {
        return menuService.removeMenuByid(menuId);
    }
}
